package DataStructure.collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CollectionsTest {
    public static void main(String[] args) {
        //实例化arrayList容器
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("d");
        list.add("c");
        list.add("b");

        //对元素排序
        Collections.sort(list);
        for(String string:list){
            System.out.println(string);
        }

        //自定义对象排序
        List<User> users = new ArrayList<>();
        User user1 = new User("a", 18);
        User user2 = new User("b", 21);
        User user3 = new User("c", 13);
        users.add(user1);
        users.add(user2);
        users.add(user3);
       Collections.sort(users);
       for(User user:users){
           System.out.println(user);
       }

    }
}
